home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / strings.swg / 0109_ASM Readln with Max Size Limit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-05-26  |  1006 b   |  46 lines

  1. {
  2. > I have seen several posts in the past few months on how to read input
  3. > not to exceed a specified input length. Here is something that I have
  4. > wrote a couple of years back to help me, and I still use it to date.
  5.  
  6. Hmmm, i think starting from today, you will use the following routine:
  7. }
  8.  
  9. Program MaxInputDemo;
  10. { Released for SWAG; Public Domain, written by Andrew Eigus
  11.   Internet: aeigus@fgate.castle.riga.lv, aeigus@kristin.cclu.lv
  12.   Fidonet: 2:5100/33 }
  13.  
  14. Procedure lReadLn(var Str : string; MaxLength : byte); assembler;
  15. { Buffered string input from a standard console device }
  16. Asm
  17.   push ds
  18.   lds si,Str
  19.   mov dx,si
  20.   mov ah,0Ah
  21.   mov bl,MaxLength
  22.   inc bl
  23.   mov [si],bl
  24.   int 21h
  25.   les di,Str
  26.   cld
  27.   inc si
  28.   lodsb
  29.   mov cl,al
  30.   stosb
  31.   xor ch,ch
  32.   jcxz @@1
  33.   rep movsb
  34. @@1:
  35.   pop ds
  36. End; { lReadLn }
  37.  
  38. var S : string;
  39.  
  40. Begin
  41.   Write('Enter a string (max 10 characters) : ');
  42.   lReadln(S, 10);
  43.   WriteLn;
  44.   WriteLn('Entered string is "', S, '"')
  45. End.
  46.